package flinkdemo.faceSink;

import java.util.List;

public class JTensor {
    private float[] data;
    private int[] shape;

    public JTensor() {
    }

    public JTensor(List<Float> data, List<Integer> shape) {
        this.data = new float[data.size()];

        int i;
        for(i = 0; i < data.size(); ++i) {
            this.data[i] = (Float)data.get(i);
        }

        this.shape = new int[shape.size()];

        for(i = 0; i < shape.size(); ++i) {
            this.shape[i] = (Integer)shape.get(i);
        }

    }

    public JTensor(List<Float> data, Integer[] shape) {
        this.data = new float[data.size()];

        int i;
        for(i = 0; i < data.size(); ++i) {
            this.data[i] = (Float)data.get(i);
        }

        this.shape = new int[shape.length];

        for(i = 0; i < shape.length; ++i) {
            this.shape[i] = shape[i];
        }

    }

    public JTensor(List<Float> data, int[] shape) {
        this.data = new float[data.size()];

        int i;
        for(i = 0; i < data.size(); ++i) {
            this.data[i] = (Float)data.get(i);
        }

        this.shape = new int[shape.length];

        for(i = 0; i < shape.length; ++i) {
            this.shape[i] = shape[i];
        }

    }

    public JTensor(float[] data, List<Integer> shape) {
        this.data = new float[data.length];

        int i;
        for(i = 0; i < data.length; ++i) {
            this.data[i] = data[i];
        }

        this.shape = new int[shape.size()];

        for(i = 0; i < shape.size(); ++i) {
            this.shape[i] = (Integer)shape.get(i);
        }

    }

    public JTensor(float[] data, Integer[] shape) {
        this.data = new float[data.length];

        int i;
        for(i = 0; i < data.length; ++i) {
            this.data[i] = data[i];
        }

        this.shape = new int[shape.length];

        for(i = 0; i < shape.length; ++i) {
            this.shape[i] = shape[i];
        }

    }

    public JTensor(float[] data, int[] shape) {
        this.data = new float[data.length];

        int i;
        for(i = 0; i < data.length; ++i) {
            this.data[i] = data[i];
        }

        this.shape = new int[shape.length];

        for(i = 0; i < shape.length; ++i) {
            this.shape[i] = shape[i];
        }

    }

    public JTensor(float[] data, int[] shape, boolean copy) {
        if (copy) {
            this.data = new float[data.length];

            int i;
            for(i = 0; i < data.length; ++i) {
                this.data[i] = data[i];
            }

            this.shape = new int[shape.length];

            for(i = 0; i < shape.length; ++i) {
                this.shape[i] = shape[i];
            }
        } else {
            this.data = data;
            this.shape = shape;
        }

    }

    public float[] getData() {
        return this.data;
    }

    public void setData(float[] data) {
        this.data = data;
    }

    public int[] getShape() {
        return this.shape;
    }

    public void setShape(int[] shape) {
        this.shape = shape;
    }

    public static String toString(int[] a) {
        if (a == null) {
            return "null";
        } else {
            int iMax = a.length - 1;
            if (iMax == -1) {
                return "[]";
            } else {
                int max = Math.min(500, iMax);
                StringBuilder b = new StringBuilder();
                b.append('[');
                int i = 0;

                while(true) {
                    b.append(a[i]);
                    if (i == max && i < iMax) {
                        return b.append(", ... ]").toString();
                    }

                    if (i == iMax) {
                        return b.append(']').toString();
                    }

                    b.append(", ");
                    ++i;
                }
            }
        }
    }

    public static String toString(float[] a) {
        if (a == null) {
            return "null";
        } else {
            int iMax = a.length - 1;
            if (iMax == -1) {
                return "[]";
            } else {
                int max = Math.min(500, iMax);
                StringBuilder b = new StringBuilder();
                b.append('[');
                int i = 0;

                while(true) {
                    b.append(a[i]);
                    if (i == max && i < iMax) {
                        return b.append(", ... ]").toString();
                    }

                    if (i == iMax) {
                        return b.append(']').toString();
                    }

                    b.append(", ");
                    ++i;
                }
            }
        }
    }

    @Override
    public String toString() {
        return "JTensor{data=" + toString(this.data) + ", shape=" + toString(this.shape) + '}';
    }
}
